const app = getApp();
Page({
    data: {
        com: 'sf',
        company: '',
        list: [],
        no: '',
        status: '0',  // 1为已签收
        status_detail: null,
        resultcode: 200,
        reason: '成功的返回',
        title:'查不到物流信息',
        isshow:true
    },
    onLoad(query) {
         
        console.log("=================",query)
        let data = JSON.parse(query.param)

        const request = {
            receiverPhone:data.receiverPhone,
            com:data.com,
            no:data.no,
        }
        
        if (data.com == "sh") {
            let data = {
                company: '上门自取',
                list: [],
                no: '无',
                status: 0
            }
            this.setData(data)
            return
        }

        console.log(query)
        let oldtime = my.getStorageSync({ key: "time" });
        let newtime = 0
        if (oldtime.data != null) {
            let time = Date.parse(new Date())
            newtime = time - oldtime.data
        } else {
            newtime = 900001
            let time = Date.parse(new Date())
            my.setStorageSync({
                key: "time",
                data: time
            })
        }
        
        
        let msg = my.getStorageSync({ key: JSON.stringify(data.id) });
        if (msg.data != null && newtime < 900000) {
            this.setData(msg.data)
        } else {
            this.getLogistics(data.id, request)
            let time = Date.parse(new Date())
            my.setStorageSync({
                key: "time",
                data: time
            })
            console.log("===================>>",data.id, request)
        }
    },
    getLogistics(id, data) {        
        app.order.getOne(id,data)
        .then(res=>{
            console.log("=======================>>",res)
            let msg = res.data.result
            if (msg==null){
                this.setData({
                    no: data.no,
                    company:'',
                    isshow: false
                })
                return false
            }
            msg.list.reverse()
            my.setStorageSync({
                key: JSON.stringify(id),
                data: msg,
                
            })
            this.setData(msg)
        })
    }
});
